import {Injectable} from '@nestjs/common';
import {UserRepository} from "./user.repository";
import { UserDto} from "./dto/user.dto";
import {CreateUserDto} from "./dto/create-user.dto";

@Injectable()
export class UserService {

    constructor(private readonly userRepository: UserRepository) {
    };

    // private repo = new UserRepository();

    async createMany(users: CreateUserDto[]): Promise<UserDto[]> {
        return await this.userRepository.createMany(users);
    }

    async findAll(): Promise<UserDto[]> {
        return this.userRepository.findAll();
    }

    async findById(id: number): Promise<UserDto | null> {
        return await this.userRepository.findById(id);
    }

    async findByUsername(name:string): Promise<UserDto | null>{
        return await this.userRepository.findByUsername(name);
    }

    async create(userData: Omit<UserDto, 'id'>): Promise<UserDto | null> {
        return await this.userRepository.create(userData);
    }

    async update(id: number, userData: Partial<UserDto>): Promise<UserDto | null> {
        return await this.userRepository.update(id, userData);
    }

    async remove(id: number): Promise<boolean> {
        return await this.userRepository.remove(id);
    }
}
